package com.village.friend.controller;


import com.village.friend.constant.MsgCodeEnum;
import com.village.friend.dto.request.QuestionAddDto;
import com.village.friend.dto.request.QuestionDelDto;
import com.village.friend.dto.response.BaseResponse;
import com.village.friend.entity.User;
import com.village.friend.redis.RedisService;
import com.village.friend.service.UserQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户反馈表 前端控制器
 * </p>
 *
 * @author yl
 * @since 2021-09-23
 */
@RestController
@RequestMapping("/appUserQuestion")
@Slf4j
@Api(tags = "用户问题反馈管理")
public class UserQuestionController {

    @Autowired
    UserQuestionService service;

    @Autowired
    RedisService redisService;


    @ApiOperation(value = "问题反馈")
    @PostMapping(value = "/add")
    public BaseResponse<String> add(@RequestBody QuestionAddDto param) {
        if (param == null || StringUtils.isBlank(param.getQuestion())) {
            return new BaseResponse(MsgCodeEnum.PARAMS_ERROR, null);
        }
        User userRedis = redisService.getUser(param.getToken());
        service.add(userRedis.getUid(), param);
        return new BaseResponse(MsgCodeEnum.SUCCESS, null);

    }


    @ApiOperation(value = "删除问题反馈")
    @PostMapping(value = "/delete")
    public BaseResponse<String> delete(@RequestBody QuestionDelDto param) {
        if (param == null || null == param.getId()) {
            return new BaseResponse(MsgCodeEnum.PARAMS_ERROR, null);
        }
        User userRedis = redisService.getUser(param.getToken());
        service.del(userRedis.getUid(), param.getId());
        return new BaseResponse(MsgCodeEnum.SUCCESS, null);
    }


}

